package com.huc.rabbit.mq.consumer;

import com.huc.rabbit.mq.config.RabbitP2PConfig;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;


@Component
@RabbitListener(queues = {RabbitP2PConfig.QUEUE_NAME})
public class P2PMessageConsumerB {

    @RabbitHandler
    public void consumer(String msg, Channel channel, Message message) throws IOException {
        try{
            System.out.println("点对点消费模式 消费者 b:"+msg);
            channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
        }catch (Exception e){
            System.out.println("消息消费失败......");
            channel.basicNack(message.getMessageProperties().getDeliveryTag(), false, true);
        }
    }

}
